package com.deng.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.deng.entity.Usermessage;
import com.deng.service.UsermessageService;
import com.deng.service.WebSocketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class WebSocketServiceImpl implements WebSocketService {
    @Autowired
    UsermessageService usermessageService;
    @Autowired
    SimpMessagingTemplate simpMessagingTemplate;
    @Async
    @Override
    public void senMessCountToUser(Long toUserId) {
        int count=usermessageService.count(new QueryWrapper<Usermessage>().eq("to_user_id",toUserId).eq("status","0"));
        //websocket通知
        simpMessagingTemplate.convertAndSendToUser(toUserId.toString(),"/messCount",count);

    }
}
